package java8_16;

import java.util.Scanner;

public class Cd {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String name[] = new String[6];//初始订餐人姓名
        String disMegs[] = new String[6];//初始菜品信息
        int times[] = new int[6];//出事送餐时间
        String address[] = new String[6];//初始送餐地址
        int state[] = new int[6];//初始订单状态，0表示预约，1表示完成
        double sumPrice[] = new double[6];//初始订单总金额

        //初始两个订单
        name[0] = "吴亦凡";
        disMegs[0] = "腰子2份";
        times[0] = 11;
        address[0] = "南京路";
        sumPrice[0] = 98.0;
        state[0] = 1;

        name[1] = "邱";
        disMegs[1] = "皮带肉丝";
        times[1] = 18;
        address[1] = "福州路";
        sumPrice[1] = 178.0;
        state[0] = 0;
        //初始选择菜品信息
        String disNames[] = {"东坡肉", "帝王蟹", "脏脏包", "麻辣龙虾", "澳洲龙虾"};
        double price[] = {120, 999, 156, 420, 790};//价格
        int dianZan[] = new int[5];//点赞
        System.out.println("欢迎使用\"黑骑士订餐系统\"");
        String n = "o";
        go:
        do {
            System.out.println("*****************");
            System.out.println("1、我要订餐");
            System.out.println("2、查看餐袋");
            System.out.println("3、签收订单");
            System.out.println("4、删除订单");
            System.out.println("5、我要点赞");
            System.out.println("6、退出系统");
            System.out.println("*****************");
            System.out.println("请选择:");
            int num = scanner.nextInt();
            switch (num) {
                case 1: {
                    String answer = "y";
                    ok:
                    do {
                        for (int j = 0; j < name.length; j++) {
                            if (name[j] == null) {
                                System.out.println("***我要订餐 ***");
                                System.out.println("**************菜品信息************");
                                System.out.println("序号\t名称\t 价格\t点赞");
                                for (int i = 0; i < disNames.length; i++) {
                                    System.out.println((i + 1) + "\t" + disNames[i] + "\t" + price[i] + "\t" + dianZan[i]);
                                }
                                System.out.println("********************************");
                                System.out.print("请选择菜单序号: ");
                                int index = scanner.nextInt();//菜单

                                while (index > 5 || index < 1) {
                                    System.out.println("请选择1-3号菜品序号");
                                    index = scanner.nextInt();
                                    if (index > 0 && index <= 5) {
                                        break;
                                    }
                                }
                                System.out.println("请输入订餐人姓名:");
                                String nameOrdr = scanner.next();
                                System.out.println("请输入订餐数量:");
                                int numOrder = scanner.nextInt();//订单数量
                                double princeOrder = price[index - 1] * numOrder;//价格*订单数量
                                //订单总额达50元，免费送餐，否付5元送餐费
                                double rate = (princeOrder >= 50) ? 0 : 5;//餐费+运送费
                                double sumPriceOrder = princeOrder + rate;//订餐信息
                                String disMeg = disNames[index - 1] + numOrder + "份";
                                System.out.println("请输入订餐时间:");
                                int timeOrder = scanner.nextInt();
                                //订餐时间
                                while (timeOrder < 8 || timeOrder > 20) {
                                    System.out.println("订餐时间早8点到晚20点，输入:");
                                    timeOrder = scanner.nextInt();
                                }
                                System.out.print("请输入送餐地址: ");
                                String addOrder = scanner.next();
                                System.out.println("订餐成功!");//显示订餐信息
                                System.out.println("您定的是:" + disMeg);
                                System.out.println("送餐时间:" + timeOrder + "点");
                                System.out.println("餐费是:" + princeOrder + ",运费是:" + rate + ",总计: " + sumPriceOrder + "元");
                                //把订单信息保存到数组
                                name[j] = nameOrdr;
                                disMegs[j] = disMeg;
                                times[j] = timeOrder;
                                address[j] = addOrder;
                                sumPrice[j] = sumPriceOrder;
                                break;
                            } else if (j == name.length - 1) {//找到最后一个，还没有空位说明已经满了
                                System.out.println("您的餐带已满");
                                break ok;//跳出循环
                            }
                        }
                        System.out.println("是否继续点餐(y/n)");
                        answer = scanner.next();
                    } while (answer.equals("y"));
                    break;
                }
                case 2: {
                    System.out.println("***查看餐袋***");
                    System.out.println("序号 \t订餐人\t餐品信 息 \t\t送餐日期\t送餐地址\t\t订单状态\t总金额");
                    for (int i = 0; i < name.length; i++) {
                        if (name[i] != null) {
                            System.out.println((i + 1) + "\t" + name[i] + "\t" + disMegs[i] + "\t " + times[i] + "\t" + address[i] + "\t" + state[i] + "\t" + sumPrice[i]);
                        }
                    }
                    break;
                }
                case 3: {
                    System.out.println("***签收订单***");
                    System.out.print("请选择要签收的订单序号: ");
                    int orderId = scanner.nextInt();
                    while (true) {//如果输入的单号超出范围，则提示重新输入
                        if (orderId < 1 || orderId > name.length) {
                            System.out.println("请输入1-5的数字");
                            orderId = scanner.nextInt();
                        } else {
                            break;
                        }
                    }
                    boolean flag = false;//默认条件是假，设立是否找到
                    for (int i = 0; i < name.length; i++) {
                        if (name[i] != null && state[i] == 0 && orderId == i + 1) {
                            state[i] = 1;//找到元素，修改成1
                            System.out.println("编号" + (i + 1) + "的订单已签收");
                            flag = true;//表示找到
                        } else if (name[i] != null && state[i] == 1 && orderId == i + 1) {
                            System.out.println("此订单已签收，不能重复签收");
                            flag = true;//表示找到
                        }
                    }
                    if (!flag) {
                        System.out.println("没有此订单");
                    }
                    break;
                }
                case 4: {
                    String answer = "y";
                    do {
                        System.out.println("***删除订单***");
                        System.out.print("请输出要删除订单号:");
                        int deleteId = scanner.nextInt();
                        while (true) {//超出范围，重新输入
                            if (deleteId < 1 || deleteId > name.length) {
                                System.out.println("请输入1-5的数字");
                                deleteId = scanner.nextInt();
                            } else {
                                break;
                            }
                        }
                        boolean flag = false;//默认条件时间
                        for (int i = 0; i < name.length; i++) {
                            if (name[i] != null && state[i] == 1 && deleteId == i + 1) {
                                flag = true;//表示找到了,没有签收,不能删除
                                System.out.println("订单没有签收, 不能删除! ");
                                break;
                            }
                        }
                        if ((!flag)) {
                            System.out.println("您要删除的订单不存在");
                        }
                        System.out.println("是否继续删除(y/n)");
                        answer = scanner.next();
                    } while (answer.equals("y"));
                    break;
                }
                case 5: {
                    String answer = "y";
                    do {
                        System.out.println("***点赞***");
                        System.out.println("******菜品信息******");
                        System.out.println("序号\t名称\t价格\t点赞");
                        for (int i = 0; i < disNames.length; i++) {
                            System.out.println((i + 1) + "\t" + disNames[i] + "\t" + price[i] + "\t" + dianZan[i]);
                        }
                        System.out.println("************");
                        System.out.println("请选择要点赞的菜单序号");
                        int index = scanner.nextInt();//菜单序号
                        while (index > 5 || index < 1) {
                            System.out.print("请选择1-5号菜品序 号");
                            index = scanner.nextInt();
                            if (index > 0 && index <= 5) {
                                break;
                            }
                        }
                        int zan = 0;
                        for (int i = 0; i < dianZan.length; i++)
                            if (i == index - 1) {
                                zan++;
                                dianZan[i] += zan;
                                System.out.println("您为编号" + index + "菜品点赞成功! ");
                                break;
                            }
                        System.out.print("是否继续点赞 (y/n):");
                        answer = scanner.next();
                    } while (answer.equals("y"));
                    break;
                }
                case 6:
                default: {
                    break go;
                }
            }
            System.out.print("\n输入0返回（其他键退出）");
            n = scanner.next();
        } while (n.equals("0"));
        System.out.println("下次光临");
    }
}
